<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%
	String path = request.getContextPath();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>活动线索</title>
<link rel="stylesheet" type="text/css" href="<%=path%>/bc/bootstarp/css/bootstrap.min.css" /> 
<link rel="stylesheet" type="text/css" href="<%=path%>/bc/css/public.css" />
<link rel="stylesheet" type="text/css" href="<%=path%>/bc/css/index.css" />
<link rel="stylesheet" type="text/css" href="<%=path%>/bc/css/set.css" />
<style type="text/css">
select {   
  appearance:none;   
  -moz-appearance:none;   
  -webkit-appearance:none;   
}
.s_content{
	top: 0;
	left: 0;
	width: 100%;
}

.s_all_title>li:nth-of-type(2):before{
	content: '';
	display: inline-block;
	width: 0px;
	height: 0px;
	border: 6px solid #ffc105;
	margin-right: 4px;
}
.s_all_title>li:nth-of-type(3):before{
	content: '';
	display: inline-block;
	width: 0px;
	height: 0px;
	border: 6px solid #ff7469;
	margin-right: 4px;
}
.s_all_title>li:nth-of-type(4):before{
	content: '';
	display: inline-block;
	width: 0px;
	height: 0px;
	border: 6px solid #03a9f4;
	margin-right: 4px;
}
.s_all_title>li:nth-of-type(5):before{
	content: '';
	display: inline-block;
	width: 0px;
	height: 0px;
	border: 6px solid #71d260;
	margin-right: 4px;
}
.s_all_title>li:nth-of-type(6):before{
	content: '';
	display: inline-block;
	width: 0px;
	height: 0px;
	border: 6px solid #96a3f1;
	margin-right: 4px;
}
</style>
</head>
<body>
<div class="s_content fix">
    <div class="m_xmanage" path="<%=path%>">
        <a href="javascript:;">全部</a>
        <a href="javascript:;">微博线索</a>
        <a href="javascript:;" class="on">活动线索</a>
        <a href="javascript:;">智能营销线索</a>
    </div>  
    <div class="s_container">
        <ol class="fix">
            <div class="s_clue">
                <p><span>0</span> 条线索源于活动</p>
                <ul class="s_source fix">
                </ul>
            </div>
            <div class="s_all">
                <ul class="s_all_title fix">
                    <li class="s_all_on"><a href="javascript:;">全部</a></li>
                </ul>
                <table>
                    <thead>
                        <tr>
                            <th>姓名</th>
                            <th>行为</th>
                            <th>来源</th>
                            <th>时间</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                    </tbody>                
                </table>
                <div class="m_xpages">
                    <div class="mian">
                        <span>显示行数</span>
                        <select><option>10</option><option>20</option><option>50</option></select>
                        <span>共0条</span>
                        <span>1/0页</span>
                        <a href="javascript:;" class="prev pageDisable">上一页</a>
                        <a href="javascript:;" class="next pageDisable">下一页</a>
                        <span>前往</span>
                        <input type="text" value="1" class="text">
                        <span>页</span>
                    </div>
                </div>
            </div>
        </ol>
    </div>
</div>
<div class="s_popup_box j_popup_box">
    <div class="s_popup_detailed show">
        <h4><img src="<%=path%>/sys/set/images/warning.png" />删除信息</h4>
        <h5>确定要删除此账号吗？</h5>
        <p><a href="javascript:;" class="j_popup_box_cancel" onclick="javascript:$(this).parents('.j_popup_box').hide();">取消</a> <a href="javascript:;" class="j_popup_box_confirm">确定</a></p>
    </div>
</div>
</body>
<script type="text/javascript" src="<%=path%>/bc/bootstarp/js/jquery.min.js"></script>
<script type="text/javascript" src="<%=path%>/bc/js/clue_title.js"></script>
<script type="text/javascript" src="<%=path%>/js/page.js"></script>
<script type="text/javascript">
var startIndex = 0;
var pageSize = 10;
var keyWord = "";
var currentPage = 1;
var pageCount = 0;

var customerId = 0;	//客户id
var actionId = 0;	//客户行为id

$(function(){
	init();
	
	$(document).on('click','.s_all_title li',function(){
        keyWord = $(this).attr("keyWord");
        init();
    });
	
	/*聊天点击开始*/
	$(document).on("click",".s_icon_dialogue",function(){
		//初始化数据，全部设置0
		top.customerId = 0;
		top.actionId = 0;
		top.clueWeiboId = 0;
		top.writeOffId = 0;
		
		customerId = $(this).attr("customerId");
		actionId = $(this).attr("actionId");
		
		top.customerId = customerId;
		top.actionId = actionId;
		top.clueWeiboId = 0;
		
<%-- 		$.post("<%=path%>/api/customer_action/customerChatView",function(data){ --%>
			var d = top.dialog({
				fixed: true,
				zIndex: 10000,
				padding:0,
				width:1172,
				height:568,
				title:'沟通记录',
// 				content:data,
				url:"<%=path%>/api/customer_action/customerChatView",
				cancelDisplay: false,
				cancel: function () {
					if(top.customerChatChange == 1){
						top.customerChatChange = 0;
					}
					top.customerId = 0;
					top.actionId = 0;
					top.clueWeiboId = 0;
					return true;
				}
			});
			d.showModal();
// 		})
	});
	/*聊天点击结束*/
});

function init(){
	$.post("${pageContext.request.contextPath}/api/weibo/showfirstpage",function(data){
		data = eval(data);
		if(data.showstatus == 1){
			;
		}else if(data.showstatus == 0){
			$(".m_xmanage>a:eq(1)").css("display","none");
		}
	});
	
	$.post('<%=path%>/api/clue_customer/clue_activity',{"startIndex":startIndex,"pageSize":pageSize,"keyWord":keyWord},function(data){
		data = JSON.parse(data);
		
		setFirst(data.activity_name_list,data.weibo_activity_count);
		
		setSecond(data.activity_clue_list);
		
		page(data.totalCount);
		
		parent.changeFrameHeight();
	});
}

function setFirst(key_word_list,keyword_count){
	var total = 0;
	
	var startStr = "";
	var endStr = "";
	
	$(".s_all>.s_all_title").html('<li class="s_all_on" keyWord=""><a href="javascript:;">全部</a></li>');
	
	//这个循环计算总数
	for ( var i = 0; i < keyword_count.length; i++) {
		if(i >= 5){
			break;
		}
		var a = keyword_count[i];
		total += a.count;
	}
	
	for ( var i = 0; i < keyword_count.length; i++) {
		if(i >= 5){
			break;
		}
		var a = keyword_count[i];
		
        $(".s_all>.s_all_title").append('<li keyWord="'+a.activityName+'"><a href="javascript:;">'+a.activityName+'</a></li>');
        var length_baifenbi = a.count/total*100;
        if(length_baifenbi == 0)
        	length_baifenbi = 2;
        if(total == 0)
        	length_baifenbi = 2;
		startStr += '<li><i><a href="javascript:;">'+a.activityName+'</a></i><div class="progressbar_1"><div class="bar" style="width:'+length_baifenbi+'%;"></div></div><em style="padding-left:10px">'+a.count+'条</em></li>'
	}

	$(".s_clue>p>span").text(total);
	
	if(startStr+endStr != ""){
		$(".s_source").html(startStr+endStr);
	}else{
		$(".s_source").html('<div class="k_empty_content"><img src="<%=path%>/bc/images/icon_hd.png"><p>您还没有活动 <a href="<%=path%>/api/bm/ui/createActivity1" target="_parent">去创建活动&gt;</a></p></div>');
		$(".s_all").css("display","none");
	}
	
	$(".s_all>.s_all_title>li[keyWord='"+keyWord+"']").addClass('s_all_on').siblings().removeClass();
}

function setSecond(weibo_clue_list){
	var tr = "";
	for(var i = 0; i < weibo_clue_list.length; i++){
		var a = weibo_clue_list[i];
		tr += '<tr><td><img style="height:50px;width:50px;" src="'+((a.avatar == null || a.avatar == undefined || a.avatar == "") ? "<%=path%>/images/000head_pic.png" : a.avatar)+'"/><a href="javascript:;">'+a.name+'</a></td><td class="s_red">'+a.content+'</td><td>'+getSourceTitle(a.source)+'</td><td class="k_time">';
		
		var now = new Date();
		var old = new Date(a.createTimeStr);
		var m_date = parseInt((now.getTime() - old.getTime())/1000/60);
		if(m_date >= 100){
			m_date = a.createTimeStr;
		}else{
			m_date += "分钟前";
		}
		
		tr += m_date+'</td><td>'
			+'<shiro:hasPermission name="customer_clue_delete_button"><a href="javascript:;" onclick="delClueActivity('+a.id+')" class="s_icon_delect"></a></shiro:hasPermission>'
			+'<shiro:hasPermission name="customer_clue_chat_button"><a customerId="'+a.customerId+'" actionId="'+a.id+'" href="javascript:;" class="s_icon_dialogue"></a></shiro:hasPermission></td></tr>';
	}
	$("table tbody").html(tr);
}

function delClueActivity(id){
	$(".j_popup_box").show();
	$(".j_popup_box .j_popup_box_confirm").unbind("click");
	$(".j_popup_box .j_popup_box_confirm").one("click",function(){
		$.post("<%=path%>/api/clue_customer/delClueActivity",{clueActivityId:id},function(data){
			init();
			$(".j_popup_box").hide();
		});
	});
}

function getSourceTitle(source){
	console.log("-----来源--》"+source);
	var title;
	switch (source) {
	case "1":
		title="微博";
		break;
	case "2":
		title="微信";
		break;
	case "3":
		title="QQ";
		break;
	case "4":
		title="活动";
		break;
	case "5":
		title="pc网页";
		break;
	default:
		title="未知";
		break;
	}
	return title;
	
}
</script>
</html>